<?php
namespace app\index\controller;
use think\Controller;
use think\Request;
use think\Db;

class Register extends  Controller{

    public  function  register(){

        $res = Request::instance();
        $url = $res->root(true);
        return view('register',compact('url'));
    }


    public  function  logo(){
    $res = Request::instance();
        $url = $res->root(true);
    if($res->isPost()){
        $compayname = input('post.compayname');
        $name = input('post.name');
        $mobile  = input('post.mobile');
        $wechat = input('post.wechat');

        $arr = [
            'compayname'=>$compayname,
            'name'=>$name,
            'phone'=>$mobile,
            'wechat'=>$wechat
        ];
        $bool = Db::name('gp')->insert($arr);
        $sql = Db::name('gp')->getLastSql();
        if($bool){
            $this->success('注册成功',"{$url}/index/register/register","",99999999);
        }
    }


}
//验证用户名
    public  function  yz_name(){
        $c = $this->yz_user('name','姓名未注册','姓名已注册');
        return json($c);
    }

//验证身份证
    public  function  yz_card(){
        $c = $this->yz_user('card','身份证未注册','身份证已注册');
        return json($c);
    }
//    验证手机号
    public  function  yz_mobile(){
    $m = $this->yz_user('phone','手机号未注册','手机号已注册');
    return json($m);
    }
//    验证银行卡
    public  function  yz_bark(){
        $b = $this->yz_user('bank_card','银行卡可用','银行卡已注册');
        return json($b);
    }
//验证微信号
    public  function  yz_wechat(){
        $w = $this->yz_user('wechat','微信可用','微信已注册');
        return json($w);
    }


    public  function  yz_user($mysql_ziduan,$suc_msg,$error_msg){
        $res = Request::instance();
        if($res->isPost()){

            $name = input('post.n');
            $arr = Db::name('consult')->where([$mysql_ziduan=>$name])->select();
            if(!empty($arr)){
                return ['error'=>1,'msg'=>$error_msg];
            }else{
                return ['error'=>0,'msg'=>$suc_msg];
            }
        }
    }

    public  function  jr_logo(){
        $res = Request::instance();
        $url = $res->root(true);
        if($res->isPost()){
            $name2 = input('post.name2');
            $card2 = input('post.card2');
            $mobile2 = input('post.mobile2');
            $account2 = input('post.account2');
            $accountbank2 = input('post.accountbank2');
            $wechat2 = input('post.wechat2');
            $money = input('post.money');
            $arr = [
                'name'=>$name2,
                'card'=>$card2,
                'phone'=>$mobile2,
                'bank_card'=>$account2,
                'account'=>$accountbank2,
                'wechat'=>$wechat2,
                'money'=>$money
            ];
            $bool = Db::name('consult')->insert($arr);
            if($bool){
                $this->success('注册成功',"{$url}/index/register/register","",10);
            }

        }
    }



}